#include <stdio.h>
#include "include/libui-char-status.h"
#include <Elementary.h>
#include <libcal-character.h>
#include <Edje.h>
#include <Ecore.h>
#include <Edje_Edit.h>


static Evas_Object* load_edj(Evas_Object* win_obj, char* filepath, char* groupname){
	Evas_Object* ret;
	ret=elm_layout_add(win_obj);
	elm_layout_file_set(ret, filepath, groupname);
	elm_win_resize_object_add(win_obj, ret);
	return ret;
}

Evas_Object* ui_char_status_create(Evas_Object* win_main, int id){
	void* libcal_character_object = libcal_create_object();
	Evas_Object* layout_main = load_edj(win_main, "/share/calatisiad-project/calatisiad-linux/output/usr/share/edje/ui-char-status.edj", "main");
	Evas_Object* edje = elm_layout_edje_get(layout_main);
//	evas_object_show(layout_main);

	GString* ins = character_get_name(libcal_character_object, id);
//#ifdef CAL_DEBUG
	printf("%s %s %d - char name is %s \n", __FILE__, __func__, __LINE__, ins->str);
//#endif
	edje_edit_state_text_set(edje, "name", "default 0", ins->str);
	g_string_free(ins, TRUE);

	ins = character_get_class(libcal_character_object, id);
	edje_edit_state_text_set(edje, "class", "default 0", ins->str);
	g_string_free(ins, TRUE);

	int ins2 = character_get_age(libcal_character_object, id);
	char x[100];
	sprintf(x, "%d", ins2);
	edje_edit_state_text_set(edje, "age", "default 0", x);
	libcal_destroy_object(libcal_character_object);

	return layout_main;
}

